package huawei.interview;

import java.util.Scanner;

/**
 * @author gh
 * @create 2021-05-31 16:07
 */
public class t1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String tag = sc.nextLine().toUpperCase();
        String[] initStr = sc.nextLine().toUpperCase().split(" ");

        if(initStr.length<4){
            return;
        }
        int i = 0;
        int index = 0, bc=0;
        while (i < initStr.length-3) {
//            System.out.println(initStr[i]);
            Integer len = Integer.valueOf(initStr[i+1]);
            if (tag.equals(initStr[i])) {
                index = i+2;
                bc = len;
                break;
            }
            i += 2+len+1;
        }
        for (int j = index+1; j <= index+bc; j++) {
            if (j!=index+1){
                System.out.print(" ");
            }
            System.out.print(initStr[j]);
        }

    }

}
